import urllib.request

# 使用urllib获取百度首页源码

baidu_url = 'http://www.baidu.com'
response = urllib.request.urlopen(baidu_url)

# HTTPResponse
print(type(response))

# 读取源码 read() 逐个字节读取，int参数标识读取多少个字节
# 解码 decode('编码格式')
# content_code = response.read().decode('utf-8')

# 读取源码 readline() 读一行
# content_code = response.readline()

# 读取源码 readlines() 读多行
# content_code = response.readlines()

# 响应状态码
print(response.getcode())

# 返回url地址
print(response.geturl())

# 获取状态信息
print(response.getheaders())
